home *** CD-ROM | disk | FTP | other *** search
/ Clickx 23 / Clickx 23.iso / DATA / wordpress / wp-admin / post.php < prev    next >
Encoding:
PHP Script  |  2005-08-14  |  27.2 KB  |  795 lines

  1. <?php
  2. require_once('admin.php');
  3.  
  4. $wpvarstoreset = array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder' );
  5.  
  6. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  7.     $wpvar = $wpvarstoreset[$i];
  8.     if (!isset($$wpvar)) {
  9.         if (empty($_POST["$wpvar"])) {
  10.             if (empty($_GET["$wpvar"])) {
  11.                 $$wpvar = '';
  12.             } else {
  13.             $$wpvar = $_GET["$wpvar"];
  14.             }
  15.         } else {
  16.             $$wpvar = $_POST["$wpvar"];
  17.         }
  18.     }
  19. }
  20.  
  21. if (isset($_POST['deletepost'])) {
  22. $action = "delete";
  23. }
  24.  
  25.     // Fix submenu highlighting for pages.
  26. if (false !== strpos($_SERVER['HTTP_REFERER'], 'edit-pages.php')) $submenu_file = 'page-new.php';
  27.  
  28. $editing = true;
  29.  
  30. switch($action) {
  31. case 'post':
  32.  
  33.     if ( !user_can_create_draft($user_ID) )
  34.         die( __('You are not allowed to create posts or drafts on this blog.') );
  35.  
  36.     $post_pingback = (int) $_POST['post_pingback'];
  37.     $content         = apply_filters('content_save_pre',  $_POST['content']);
  38.     $excerpt         = apply_filters('excerpt_save_pre',  $_POST['excerpt']);
  39.     $post_title      = apply_filters('title_save_pre',    $_POST['post_title']);
  40.     $post_categories = apply_filters('category_save_pre', $_POST['post_category']);
  41.     $post_status     = apply_filters('status_save_pre',   $_POST['post_status']);
  42.     $post_name       = apply_filters('name_save_pre',     $_POST['post_name']);
  43.     $post_parent = 0;
  44.     $menu_order  = 0;
  45.     
  46.  
  47.     if ( isset($_POST['parent_id']) )
  48.         $post_parent = (int) $_POST['parent_id'];
  49.  
  50.     if ( isset($_POST['menu_order']) )
  51.         $menu_order = (int) $_POST['menu_order'];
  52.  
  53.     if (! empty($_POST['post_author_override'])) {
  54.         $post_author = (int) $_POST['post_author_override'];
  55.     } else if (! empty($_POST['post_author'])) {
  56.         $post_author = (int) $_POST['post_author'];
  57.     } else {
  58.         $post_author = (int) $_POST['user_ID'];
  59.     }
  60.     if ( !user_can_edit_user($user_ID, $post_author) )
  61.         die( __('You cannot post as this user.') );
  62.  
  63.     if ( empty($post_status) )
  64.         $post_status = 'draft';
  65.     // Double-check
  66.     if ( 'publish' == $post_status && (!user_can_create_post($user_ID)) )
  67.         $post_status = 'draft';
  68.         
  69.     $comment_status = $_POST['comment_status'];
  70.     if ( empty($comment_status) ) {
  71.         if ( !isset($_POST['advanced_view']) )
  72.             $comment_status = get_option('default_comment_status');
  73.         else
  74.             $comment_status = 'closed';
  75.         }
  76.  
  77.     $ping_status = $_POST['ping_status'];
  78.     if ( empty($ping_status) ) {
  79.         if ( !isset($_POST['advanced_view']) )
  80.             $ping_status = get_option('default_ping_status');            
  81.         else
  82.             $ping_status = 'closed';
  83.         }
  84.  
  85.     $post_password = $_POST['post_password'];
  86.     
  87.     $trackback = $_POST['trackback_url'];
  88.     $trackback = preg_replace('|\s+|', "\n", $trackback);
  89.  
  90.     if (user_can_set_post_date($user_ID) && (!empty($_POST['edit_date']))) {
  91.         $aa = $_POST['aa'];
  92.         $mm = $_POST['mm'];
  93.         $jj = $_POST['jj'];
  94.         $hh = $_POST['hh'];
  95.         $mn = $_POST['mn'];
  96.         $ss = $_POST['ss'];
  97.         $jj = ($jj > 31) ? 31 : $jj;
  98.         $hh = ($hh > 23) ? $hh - 24 : $hh;
  99.         $mn = ($mn > 59) ? $mn - 60 : $mn;
  100.         $ss = ($ss > 59) ? $ss - 60 : $ss;
  101.         $now = "$aa-$mm-$jj $hh:$mn:$ss";
  102.         $now_gmt = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
  103.     } else {
  104.         $now = current_time('mysql');
  105.         $now_gmt = current_time('mysql', 1);
  106.     }
  107.  
  108.     // What to do based on which button they pressed
  109.     if ('' != $_POST['saveasdraft']) $post_status = 'draft';
  110.     if ('' != $_POST['saveasprivate']) $post_status = 'private';
  111.     if ('' != $_POST['publish']) $post_status = 'publish';
  112.     if ('' != $_POST['advanced']) $post_status = 'draft';
  113.     if ('' != $_POST['savepage']) $post_status = 'static';
  114.  
  115.  
  116.  
  117.     $id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->posts'");
  118.     $post_ID = $id_result->Auto_increment;
  119.  
  120.     if ( empty($post_name) ) {
  121.         if ( 'draft' != $post_status )
  122.             $post_name = sanitize_title($post_title, $post_ID);
  123.     } else {
  124.         $post_name = sanitize_title($post_name, $post_ID);
  125.     }
  126.  
  127.     if ('publish' == $post_status) {
  128.         $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
  129.         if ($post_name_check) {
  130.             $suffix = 2;
  131.             while ($post_name_check) {
  132.                 $alt_post_name = $post_name . "-$suffix";
  133.                 $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
  134.                 $suffix++;
  135.             }
  136.             $post_name = $alt_post_name;
  137.         }
  138.     }
  139.  
  140.     $postquery ="INSERT INTO $wpdb->posts
  141.             (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order)
  142.             VALUES
  143.             ('$post_ID', '$post_author', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt', '$post_parent', '$menu_order')
  144.             ";
  145.  
  146.     $result = $wpdb->query($postquery);
  147.  
  148.     if (!empty($_POST['mode'])) {
  149.     switch($_POST['mode']) {
  150.         case 'bookmarklet':
  151.             $location = 'bookmarklet.php?a=b';
  152.             break;
  153.         case 'sidebar':
  154.             $location = 'sidebar.php?a=b';
  155.             break;
  156.         default:
  157.             $location = 'post.php';
  158.             break;
  159.         }
  160.     } else {
  161.         $location = 'post.php?posted=true';
  162.     }
  163.  
  164.     if ( 'static' == $_POST['post_status'] )
  165.         $location = "page-new.php?saved=true";
  166.  
  167.     if ( '' != $_POST['advanced'] || isset($_POST['save']) )
  168.         $location = "post.php?action=edit&post=$post_ID";
  169.  
  170.     header("Location: $location"); // Send user on their way while we keep working
  171.  
  172.     // Insert categories
  173.     // Check to make sure there is a category, if not just set it to some default
  174.     if (!$post_categories) $post_categories[] = get_option('default_category');
  175.     foreach ($post_categories as $post_category) {
  176.         // Double check it's not there already
  177.         $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_ID AND category_id = $post_category");
  178.  
  179.          if (!$exists) { 
  180.             $wpdb->query("
  181.             INSERT INTO $wpdb->post2cat
  182.             (post_id, category_id)
  183.             VALUES
  184.             ($post_ID, $post_category)
  185.             ");
  186.         }
  187.     }
  188.  
  189.     add_meta($post_ID);
  190.  
  191.     $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
  192.  
  193.     do_action('save_post', $post_ID);
  194.  
  195.     if ('publish' == $post_status) {
  196.         do_action('publish_post', $post_ID);
  197.         if ($post_pingback)
  198.             register_shutdown_function('pingback', $content, $post_ID);
  199.         register_shutdown_function('do_enclose', $content, $post_ID );
  200.         register_shutdown_function('do_trackbacks', $post_ID);
  201.     }
  202.  
  203.     if ($post_status == 'static') {
  204.         generate_page_rewrite_rules();
  205.         add_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'], true);
  206.     }
  207.  
  208.     require_once('admin-header.php');
  209.  
  210.     exit();
  211.     break;
  212.  
  213. case 'edit':
  214.     $title = __('Edit');
  215.  
  216.     require_once('admin-header.php');
  217.  
  218.     $post = $post_ID = $p = (int) $_GET['post'];
  219.  
  220.     if ( !user_can_edit_post($user_ID, $post_ID) )
  221.         die ( __('You are not allowed to edit this post.') );
  222.         
  223.     $postdata = &get_post($post_ID);
  224.     $content = $postdata->post_content;
  225.     $content = format_to_edit($content);
  226.     $content = apply_filters('content_edit_pre', $content);
  227.     $excerpt = $postdata->post_excerpt;
  228.     $excerpt = format_to_edit($excerpt);
  229.     $excerpt = apply_filters('excerpt_edit_pre', $excerpt);
  230.     $edited_post_title = format_to_edit($postdata->post_title);
  231.     $edited_post_title = apply_filters('title_edit_pre', $edited_post_title);
  232.     $post_status = $postdata->post_status;
  233.     $comment_status = $postdata->comment_status;
  234.     $ping_status = $postdata->ping_status;
  235.     $post_password = $postdata->post_password;
  236.     $to_ping = $postdata->to_ping;
  237.     $pinged = $postdata->pinged;
  238.     $post_name = $postdata->post_name;
  239.     $post_parent = $postdata->post_parent;
  240.     $post_author = $postdata->post_author;
  241.     $menu_order = $postdata->menu_order;
  242.  
  243.     if( 'private' == $postdata->post_status && $postdata->post_author != $user_ID )
  244.         die ( __('You are not allowed to view other users\' private posts.') );
  245.  
  246.     if ($post_status == 'static') {
  247.         $page_template = get_post_meta($post_ID, '_wp_page_template', true);
  248.         include('edit-page-form.php');
  249.     } else {
  250.         include('edit-form-advanced.php');
  251.     }
  252.  
  253.     $post = &$postdata;
  254.     ?>
  255.     <div id='preview' class='wrap'>
  256.     <h2><?php _e('Post Preview (updated when post is saved)'); ?></h2>
  257.     <h3 class="storytitle" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__("Permanent Link: %s"), get_the_title()); ?>"><?php the_title(); ?></a></h3>
  258.     <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(','); ?> — <?php the_author() ?> @ <?php the_time() ?></div>
  259.  
  260.     <div class="storycontent">
  261.     <?php 
  262.     $content = apply_filters('the_content', $post->post_content);
  263.     echo $content;
  264.     ?>
  265.     </div>
  266.     </div>
  267.     <?php
  268.     break;
  269.  
  270. case 'editpost':
  271.     // die(var_dump('<pre>', $_POST));
  272.     if (!isset($blog_ID)) {
  273.         $blog_ID = 1;
  274.     }
  275.     $post_ID = (int) $_POST['post_ID'];
  276.  
  277.     if (!user_can_edit_post($user_ID, $post_ID, $blog_ID))
  278.         die( __('You are not allowed to edit this post.') );
  279.  
  280.     $post_categories = $_POST['post_category'];
  281.     if (!$post_categories) $post_categories[] = 1;
  282.     $content = apply_filters('content_save_pre', $_POST['content']);
  283.     $excerpt = apply_filters('excerpt_save_pre', $_POST['excerpt']);
  284.     $post_title = $_POST['post_title'];
  285.     $prev_status = $_POST['prev_status'];
  286.     $post_status = $_POST['post_status'];
  287.     $menu_order = (int) $_POST['menu_order'];
  288.     if (! empty($_POST['post_author_override'])) {
  289.         $post_author = (int) $_POST['post_author_override'];
  290.     } else if (! empty($_POST['post_author'])) {
  291.         $post_author = (int) $_POST['post_author'];
  292.     } else {
  293.         $post_author = (int) $_POST['user_ID'];
  294.     }
  295.     if ( !user_can_edit_user($user_ID, $post_author) )
  296.         die( __('You cannot post as this user.') );
  297.  
  298.     $comment_status = $_POST['comment_status'];
  299.     if (empty($comment_status)) $comment_status = 'closed';
  300.     //if (!$_POST['comment_status']) $comment_status = get_settings('default_comment_status');
  301.  
  302.     $ping_status = $_POST['ping_status'];
  303.     if (empty($ping_status)) $ping_status = 'closed';
  304.     //if (!$_POST['ping_status']) $ping_status = get_settings('default_ping_status');
  305.     $post_password = $_POST['post_password'];
  306.     $post_name = $_POST['post_name'];
  307.  
  308.     $post_parent = 0;
  309.     if (isset($_POST['parent_id'])) {
  310.         $post_parent = (int) $_POST['parent_id'];
  311.     }
  312.  
  313.     $trackback = $_POST['trackback_url'];
  314.     // Format trackbacks
  315.     $trackback = preg_replace('|\s+|', '\n', $trackback);
  316.     
  317.     if (isset($_POST['publish'])) $post_status = 'publish';
  318.     // Double-check
  319.     if ( 'publish' == $post_status && (!user_can_create_post($user_ID)) )
  320.         $post_status = 'draft';
  321.  
  322.     if ( empty($post_name) ) {
  323.         if ( 'draft' != $post_status )
  324.             $post_name = sanitize_title($post_title, $post_ID);
  325.     } else {
  326.         $post_name = sanitize_title($post_name, $post_ID);
  327.     }
  328.  
  329.     if ('publish' == $post_status) {
  330.         $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
  331.         if ($post_name_check) {
  332.             $suffix = 2;
  333.             while ($post_name_check) {
  334.                 $alt_post_name = $post_name . "-$suffix";
  335.                 $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
  336.                 $suffix++;
  337.             }
  338.             $post_name = $alt_post_name;
  339.         }
  340.     }
  341.  
  342.     if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
  343.         $aa = $_POST['aa'];
  344.         $mm = $_POST['mm'];
  345.         $jj = $_POST['jj'];
  346.         $hh = $_POST['hh'];
  347.         $mn = $_POST['mn'];
  348.         $ss = $_POST['ss'];
  349.         $jj = ($jj > 31) ? 31 : $jj;
  350.         $hh = ($hh > 23) ? $hh - 24 : $hh;
  351.         $mn = ($mn > 59) ? $mn - 60 : $mn;
  352.         $ss = ($ss > 59) ? $ss - 60 : $ss;
  353.         $datemodif = ", post_date = '$aa-$mm-$jj $hh:$mn:$ss'";
  354.     $datemodif_gmt = ", post_date_gmt = '".get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss")."'";
  355.     } else {
  356.         $datemodif = '';
  357.         $datemodif_gmt = '';
  358.     }
  359.  
  360.     $now = current_time('mysql');
  361.     $now_gmt = current_time('mysql', 1);
  362.  
  363.     $result = $wpdb->query("
  364.         UPDATE $wpdb->posts SET
  365.             post_content = '$content',
  366.             post_excerpt = '$excerpt',
  367.             post_title = '$post_title'"
  368.             .$datemodif_gmt
  369.             .$datemodif.",            
  370.             post_status = '$post_status',
  371.             comment_status = '$comment_status',
  372.             ping_status = '$ping_status',
  373.             post_author = '$post_author',
  374.             post_password = '$post_password',
  375.             post_name = '$post_name',
  376.             to_ping = '$trackback',
  377.             post_modified = '$now',
  378.             post_modified_gmt = '$now_gmt',
  379.             menu_order = '$menu_order',
  380.             post_parent = '$post_parent'
  381.         WHERE ID = $post_ID ");
  382.  
  383.     if ($_POST['save']) {
  384.         $location = $_SERVER['HTTP_REFERER'];
  385.     } elseif ($_POST['updatemeta']) {
  386.         $location = $_SERVER['HTTP_REFERER'] . '&message=2#postcustom';
  387.     } elseif ($_POST['deletemeta']) {
  388.         $location = $_SERVER['HTTP_REFERER'] . '&message=3#postcustom';
  389.     } elseif (isset($_POST['referredby']) && $_POST['referredby'] != $_SERVER['HTTP_REFERER']) {
  390.         $location = $_POST['referredby'];
  391.         if ( $_POST['referredby'] == 'redo' )
  392.             $location = get_permalink( $post_ID );
  393.     } else {
  394.         $location = 'post.php';
  395.     }
  396.     header ('Location: ' . $location); // Send user on their way while we keep working
  397.  
  398.     // Meta Stuff
  399.     if ($_POST['meta']) :
  400.         foreach ($_POST['meta'] as $key => $value) :
  401.             update_meta($key, $value['key'], $value['value']);
  402.         endforeach;
  403.     endif;
  404.  
  405.     if ($_POST['deletemeta']) :
  406.         foreach ($_POST['deletemeta'] as $key => $value) :
  407.             delete_meta($key);
  408.         endforeach;
  409.     endif;
  410.  
  411.     add_meta($post_ID);
  412.  
  413.     // Now it's category time!
  414.     // First the old categories
  415.     $old_categories = $wpdb->get_col("SELECT category_id FROM $wpdb->post2cat WHERE post_id = $post_ID");
  416.     
  417.     // Delete any?
  418.     foreach ($old_categories as $old_cat) {
  419.         if (!in_array($old_cat, $post_categories)) // If a category was there before but isn't now
  420.             $wpdb->query("DELETE FROM $wpdb->post2cat WHERE category_id = $old_cat AND post_id = $post_ID LIMIT 1");
  421.     }
  422.     
  423.     // Add any?
  424.     foreach ($post_categories as $new_cat) {
  425.         if (!in_array($new_cat, $old_categories))
  426.             $wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_ID, $new_cat)");
  427.     }
  428.  
  429.     if ($prev_status != 'publish' && $post_status == 'publish')
  430.         do_action('private_to_published', $post_ID);
  431.  
  432.     do_action('edit_post', $post_ID);
  433.  
  434.     if ($post_status == 'publish') {
  435.         do_action('publish_post', $post_ID);
  436.         register_shutdown_function('do_trackbacks', $post_ID);
  437.         register_shutdown_function('do_enclose', $content, $post_ID );
  438.         if ( get_option('default_pingback_flag') )
  439.             register_shutdown_function('pingback', $content, $post_ID);
  440.     }
  441.  
  442.     if ($post_status == 'static') {
  443.         generate_page_rewrite_rules();
  444.  
  445.         if ( ! update_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'])) {
  446.             add_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'], true);
  447.         }
  448.     }
  449.  
  450.     exit();
  451.     break;
  452.  
  453. case 'delete':
  454.     check_admin_referer();
  455.  
  456.     $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
  457.     
  458.     if (!user_can_delete_post($user_ID, $post_id)) {
  459.         die( __('You are not allowed to delete this post.') );
  460.     }
  461.  
  462.     if (! wp_delete_post($post_id))
  463.         die( __('Error in deleting...') );
  464.  
  465.     $sendback = $_SERVER['HTTP_REFERER'];
  466.     if (strstr($sendback, 'post.php')) $sendback = get_settings('siteurl') .'/wp-admin/post.php';
  467.     $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
  468.     header ('Location: ' . $sendback);
  469.     generate_page_rewrite_rules();
  470.     do_action('delete_post', $post_id);
  471.     break;
  472.  
  473. case 'editcomment':
  474.     $title = __('Edit Comment');
  475.     $parent_file = 'edit.php';
  476.     require_once ('admin-header.php');
  477.  
  478.     get_currentuserinfo();
  479.  
  480.     $comment = (int) $_GET['comment'];
  481.     $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
  482.  
  483.     if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  484.         die( __('You are not allowed to edit comments on this post.') );
  485.     }
  486.  
  487.     $content = $commentdata['comment_content'];
  488.     $content = format_to_edit($content);
  489.     $content = apply_filters('comment_edit_pre', $content);
  490.     
  491.     $comment_status = $commentdata['comment_approved'];
  492.  
  493.     include('edit-form-comment.php');
  494.  
  495.     break;
  496.  
  497. case 'confirmdeletecomment':
  498.  
  499.     require_once('./admin-header.php');
  500.  
  501.     $comment = (int) $_GET['comment'];
  502.     $p = (int) $_GET['p'];
  503.     $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  504.  
  505.     if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  506.         die( __('You are not allowed to delete comments on this post.') );
  507.     }
  508.  
  509.     echo "<div class=\"wrap\">\n";
  510.     echo "<p>" . __('<strong>Caution:</strong> You are about to delete the following comment:') . "</p>\n";
  511.     echo "<table border=\"0\">\n";
  512.     echo "<tr><td>" . __('Author:') . "</td><td>" . $commentdata["comment_author"] . "</td></tr>\n";
  513.     echo "<tr><td>" . __('E-mail:') . "</td><td>" . $commentdata["comment_author_email"] . "</td></tr>\n";
  514.     echo "<tr><td>". __('URL:') . "</td><td>" . $commentdata["comment_author_url"] . "</td></tr>\n";
  515.     echo "<tr><td>". __('Comment:') . "</td><td>" . stripslashes($commentdata["comment_content"]) . "</td></tr>\n";
  516.     echo "</table>\n";
  517.     echo "<p>" . __('Are you sure you want to do that?') . "</p>\n";
  518.  
  519.     echo "<form action='".get_settings('siteurl')."/wp-admin/post.php' method='get'>\n";
  520.     echo "<input type=\"hidden\" name=\"action\" value=\"deletecomment\" />\n";
  521.     echo "<input type=\"hidden\" name=\"p\" value=\"$p\" />\n";
  522.     echo "<input type=\"hidden\" name=\"comment\" value=\"$comment\" />\n";
  523.     echo "<input type=\"hidden\" name=\"noredir\" value=\"1\" />\n";
  524.     echo "<input type=\"submit\" value=\"" . __('Yes') . "\" />";
  525.     echo "  ";
  526.     echo "<input type=\"button\" value=\"" . __('No') . "\" onclick=\"self.location='". get_settings('siteurl') ."/wp-admin/edit.php?p=$p&c=1#comments';\" />\n";
  527.     echo "</form>\n";
  528.     echo "</div>\n";
  529.  
  530.     break;
  531.  
  532. case 'deletecomment':
  533.  
  534.     check_admin_referer();
  535.  
  536.     $comment = (int) $_GET['comment'];
  537.     $p = (int) $_GET['p'];
  538.     if (isset($_GET['noredir'])) {
  539.         $noredir = true;
  540.     } else {
  541.         $noredir = false;
  542.     }
  543.  
  544.     $postdata = get_post($p) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  545.     $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
  546.  
  547.     if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  548.         die( __('You are not allowed to edit comments on this post.') );
  549.     }
  550.  
  551.     wp_set_comment_status($comment, "delete");
  552.     do_action('delete_comment', $comment);
  553.  
  554.     if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
  555.         header('Location: ' . $_SERVER['HTTP_REFERER']);
  556.     } else {
  557.         header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  558.     }
  559.  
  560.     break;
  561.  
  562. case 'unapprovecomment':
  563.  
  564.     require_once('./admin-header.php');
  565.  
  566.     check_admin_referer();
  567.  
  568.     $comment = (int) $_GET['comment'];
  569.     $p = (int) $_GET['p'];
  570.     if (isset($_GET['noredir'])) {
  571.         $noredir = true;
  572.     } else {
  573.         $noredir = false;
  574.     }
  575.  
  576.     $commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  577.  
  578.     if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  579.         die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') );
  580.     }
  581.  
  582.     wp_set_comment_status($comment, "hold");
  583.  
  584.     if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
  585.         header('Location: ' . $_SERVER['HTTP_REFERER']);
  586.     } else {
  587.         header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  588.     }
  589.  
  590.     break;
  591.  
  592. case 'mailapprovecomment':
  593.  
  594.     $comment = (int) $_GET['comment'];
  595.  
  596.     $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  597.  
  598.     if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  599.         die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
  600.     }
  601.  
  602.     if ('1' != $commentdata['comment_approved']) {
  603.         wp_set_comment_status($comment, 'approve');
  604.         if (true == get_option('comments_notify'))
  605.             wp_notify_postauthor($comment);
  606.     }
  607.  
  608.     header('Location: ' . get_option('siteurl') . '/wp-admin/moderation.php?approved=1');
  609.  
  610.     break;
  611.  
  612. case 'approvecomment':
  613.  
  614.     $comment = (int) $_GET['comment'];
  615.     $p = (int) $_GET['p'];
  616.     if (isset($_GET['noredir'])) {
  617.         $noredir = true;
  618.     } else {
  619.         $noredir = false;
  620.     }
  621.     $commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  622.  
  623.     if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  624.         die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
  625.     }
  626.  
  627.     wp_set_comment_status($comment, "approve");
  628.     if (get_settings("comments_notify") == true) {
  629.         wp_notify_postauthor($comment);
  630.     }
  631.  
  632.  
  633.     if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
  634.         header('Location: ' . $_SERVER['HTTP_REFERER']);
  635.     } else {
  636.         header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  637.     }
  638.  
  639.     break;
  640.  
  641. case 'editedcomment':
  642.  
  643.     $comment_ID = (int) $_POST['comment_ID'];
  644.     $comment_post_ID = (int) $_POST['comment_post_ID'];
  645.     $newcomment_author = $_POST['newcomment_author'];
  646.     $newcomment_author_email = $_POST['newcomment_author_email'];
  647.     $newcomment_author_url = $_POST['newcomment_author_url'];
  648.     $comment_status = $_POST['comment_status'];
  649.  
  650.     if (!user_can_edit_post_comments($user_ID, $comment_post_ID)) {
  651.         die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.') );
  652.     }
  653.  
  654.     if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
  655.         $aa = $_POST['aa'];
  656.         $mm = $_POST['mm'];
  657.         $jj = $_POST['jj'];
  658.         $hh = $_POST['hh'];
  659.         $mn = $_POST['mn'];
  660.         $ss = $_POST['ss'];
  661.         $jj = ($jj > 31) ? 31 : $jj;
  662.         $hh = ($hh > 23) ? $hh - 24 : $hh;
  663.         $mn = ($mn > 59) ? $mn - 60 : $mn;
  664.         $ss = ($ss > 59) ? $ss - 60 : $ss;
  665.         $datemodif = ", comment_date = '$aa-$mm-$jj $hh:$mn:$ss'";
  666.     } else {
  667.         $datemodif = '';
  668.     }
  669.     $content = apply_filters('comment_save_pre', $_POST['content']);
  670.  
  671.     $result = $wpdb->query("
  672.         UPDATE $wpdb->comments SET
  673.             comment_content = '$content',
  674.             comment_author = '$newcomment_author',
  675.             comment_author_email = '$newcomment_author_email',
  676.             comment_approved = '$comment_status',
  677.             comment_author_url = '$newcomment_author_url'".$datemodif."
  678.         WHERE comment_ID = $comment_ID"
  679.         );
  680.  
  681.     $referredby = $_POST['referredby'];
  682.     if (!empty($referredby)) {
  683.         header('Location: ' . $referredby);
  684.     } else {
  685.         header ("Location: edit.php?p=$comment_post_ID&c=1#comments");
  686.     }
  687.     do_action('edit_comment', $comment_ID);
  688.     break;
  689.  
  690. default:
  691.     $title = __('Create New Post');
  692.     require_once ('./admin-header.php');
  693. ?>
  694. <?php if ( isset($_GET['posted']) ) : ?>
  695. <div class="updated"><p><?php printf(__('Post saved. <a href="%s">View site »</a>'), get_bloginfo('home')); ?></p></div>
  696. <?php endif; ?>
  697. <?php
  698.     if (user_can_create_draft($user_ID)) {
  699.         $action = 'post';
  700.         get_currentuserinfo();
  701.         $drafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = $user_ID");
  702.         if ($drafts) {
  703.             ?>
  704.             <div class="wrap">
  705.             <p><strong><?php _e('Your Drafts:') ?></strong>
  706.             <?php
  707.             $i = 0;
  708.             foreach ($drafts as $draft) {
  709.                 if (0 != $i)
  710.                     echo ', ';
  711.                 $draft->post_title = stripslashes($draft->post_title);
  712.                 if ($draft->post_title == '')
  713.                     $draft->post_title = sprintf(__('Post # %s'), $draft->ID);
  714.                 echo "<a href='post.php?action=edit&post=$draft->ID' title='" . __('Edit this draft') . "'>$draft->post_title</a>";
  715.                 ++$i;
  716.                 }
  717.             ?>.</p>
  718.             </div>
  719.             <?php
  720.         }
  721.         //set defaults
  722.         $post_status = 'draft';
  723.         $comment_status = get_settings('default_comment_status');
  724.         $ping_status = get_settings('default_ping_status');
  725.         $post_pingback = get_settings('default_pingback_flag');
  726.         $default_post_cat = get_settings('default_category');
  727.  
  728.         $content = wp_specialchars($content);
  729.         $content = apply_filters('default_content', $content);
  730.         $edited_post_title = apply_filters('default_title', $edited_post_title);
  731.         $excerpt = apply_filters('default_excerpt', $excerpt);
  732.  
  733.         if (get_settings('advanced_edit')) {
  734.             include('edit-form-advanced.php');
  735.         } else {
  736.             include('edit-form.php');
  737.         }
  738. ?>
  739. <div class="wrap">
  740. <?php _e('<h3>WordPress bookmarklet</h3>
  741. <p>You can drag the following link to your links bar or add it to your bookmarks and when you "Press it" it will open up a popup window with information and a link to the site you’re currently browsing so you can make a quick post about it. Try it out:</p>') ?>
  742. <p>
  743.  
  744. <?php
  745. $bookmarklet_height= (get_settings('use_trackback')) ? 480 : 440;
  746.  
  747. if ($is_NS4 || $is_gecko) {
  748. ?>
  749. <a href="javascript:if(navigator.userAgent.indexOf('Safari') >= 0){Q=getSelection();}else{Q=document.selection?document.selection.createRange().text:document.getSelection();}void(window.open('<?php echo get_settings('siteurl') ?>/wp-admin/bookmarklet.php?text='+encodeURIComponent(Q)+'&popupurl='+encodeURIComponent(location.href)+'&popuptitle='+encodeURIComponent(document.title),'<?php _e('WordPress bookmarklet') ?>','scrollbars=yes,width=600,height=460,left=100,top=150,status=yes'));"><?php printf(__('Press It - %s'), wp_specialchars(get_settings('blogname'))); ?></a> 
  750. <?php
  751. } else if ($is_winIE) {
  752. ?>
  753. <a href="javascript:Q='';if(top.frames.length==0)Q=document.selection.createRange().text;void(btw=window.open('<?php echo get_settings('siteurl') ?>/wp-admin/bookmarklet.php?text='+encodeURIComponent(Q)+'<?php echo $bookmarklet_tbpb ?>&popupurl='+encodeURIComponent(location.href)+'&popuptitle='+encodeURIComponent(document.title),'bookmarklet','scrollbars=yes,width=600,height=<?php echo $bookmarklet_height ?>,left=100,top=150,status=yes'));btw.focus();"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a>
  754. <script type="text/javascript">
  755. <!--
  756. function oneclickbookmarklet(blah) {
  757. window.open ("profile.php?action=IErightclick", "oneclickbookmarklet", "width=500, height=450, location=0, menubar=0, resizable=0, scrollbars=1, status=1, titlebar=0, toolbar=0, screenX=120, left=120, screenY=120, top=120");
  758. }
  759. // -->
  760. </script>
  761. <br />
  762. <br />
  763. <?php _e('One-click bookmarklet:') ?><br />
  764. <a href="javascript:oneclickbookmarklet(0);"><?php _e('click here') ?></a> 
  765. <?php
  766. } else if ($is_opera) {
  767. ?>
  768. <a href="javascript:void(window.open('<?php echo get_settings('siteurl'); ?>/wp-admin/bookmarklet.php?popupurl='+escape(location.href)+'&popuptitle='+escape(document.title)+'<?php echo $bookmarklet_tbpb ?>','bookmarklet','scrollbars=yes,width=600,height=<?php echo $bookmarklet_height ?>,left=100,top=150,status=yes'));"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a> 
  769. <?php
  770. } else if ($is_macIE) {
  771. ?>
  772. <a href="javascript:Q='';if(top.frames.length==0);void(btw=window.open('<?php echo get_settings('siteurl'); ?>/wp-admin/bookmarklet.php?text='+escape(document.getSelection())+'&popupurl='+escape(location.href)+'&popuptitle='+escape(document.title)+'<?php echo $bookmarklet_tbpb ?>','bookmarklet','scrollbars=yes,width=600,height=<?php echo $bookmarklet_height ?>,left=100,top=150,status=yes'));btw.focus();"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a> 
  773. <?php
  774. }
  775. ?>
  776. </p>
  777. </div>
  778. <?php
  779. } else {
  780. ?>
  781. <div class="wrap">
  782. <p><?php printf(__('Since you’re a newcomer, you’ll have to wait for an admin to raise your level to 1, in order to be authorized to post.<br />
  783. You can also <a href="mailto:%s?subject=Promotion?">e-mail the admin</a> to ask for a promotion.<br />
  784. When you’re promoted, just reload this page and you’ll be able to blog. :)'), get_settings('admin_email')); ?>
  785. </p>
  786. </div>
  787. <?php
  788. }
  789.  
  790.     break;
  791. } // end switch
  792. /* </Edit> */
  793. include('admin-footer.php');
  794. ?>
  795.